package com.example.ex2.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)//序列化去掉空值
public class CommonResponse<T> {
    private final int status;
    private final String message;
    private final String link;

    private T data;

    private CommonResponse(int status, String message ,String link){
        this.status=status;
        this.message=message;
        this.link=link;
    }

    private CommonResponse(int status, String message, String link, T data){
        this.status=status;
        this.message=message;
        this.link = link;
        this.data=data;
    }

    public static <T> CommonResponse<T> createForSuccess(String message,String link){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(),message,link);
    }
    public static <T> CommonResponse<T> createForSuccess(T data,String link){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc(), link, data);
    }

    public static <T> CommonResponse<T> createForSuccess(String message,T data,String link){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(),message, link, data);
    }

    public static <T> CommonResponse<T> createForError(String link){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc(),link);
    }
    public static <T> CommonResponse<T> createForError(String message,String link){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(),message,link);
    }
    public static <T> CommonResponse<T> createForError(int code, String message,String link){
        return new CommonResponse<>(code,message,link);
    }

}
